<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>学生登录</title>
<link rel="stylesheet" href="common.css">
<!-- 这里是Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<script src="https://cdn.bootcss.com/jquery/2.2.4/jquery.min.js"></script>
<link href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<link href="https://cdn.bootcss.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
<script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="css/denglu.css">
<style>
	form {
		text-align: center;
		margin-top: 240px;
	}

	.btn {
		width: 50px;
		height: 30px;
	}
</style>
<?php
//判断cookie里是否存在帐号密码 如果存在获取

$stu_number = "";
$stu_password = "";

if(isset($_COOKIE["stu_number"])) {
    //获取cookie里的值
    $stu_number = $_COOKIE["stu_number"];
}

if(isset($_COOKIE["stu_password"])) {
    $stu_password = $_COOKIE["stu_password"];
}

?>

<div class="container">
    <div class="form row">
        <div class="form-horizontal col-md-offset-3" id="login_form">
            <h3 class="form-title" >欢迎登陆作业管理系统</h3>
                <ul id="myTab" class="nav nav-tabs">
                    <li class="active"><a href="#home" data-toggle="tab">学生</a></li>
                </ul>
                <div id="myTabContent" class="tab-content">
                    <div class="tab-pane fade in active" id="home">
                        <form method="post" action="" id="baoguo">
                            <div class="col-md-9">
                                <div class="form-group">
                                    <i class="fa fa-user fa-lg"></i>
                                    <input class="form-control required" type="text" placeholder="你的账户" id="username" name="stu_number"  value="<?php echo $stu_number;?>" maxlength="20"/>
                                </div>
                                <div class="form-group">
                                    <i class="fa fa-lock fa-lg"></i>
                                    <input class="form-control required" type="password" placeholder="你的密码" id="password" name="stu_password" value="<?php echo $stu_password;?>" maxlength="8"/>
                                </div>
                                <a href="register.php">还没注册？点我注册</a>
                                <div class="form-group col-md-offset-9">
                                    <input type="submit" class="btn btn-success pull-right" name="submit" value="登录">
                                    </input>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<?php
if(isset($_POST["submit"]) && $_POST["submit"] == "登录") {

    $stu_number = $_POST["stu_number"];
    $stu_password = md5($_POST["stu_password"]);

    $selectstusql = "select * from students where stu_number='$stu_number' and stu_password='$stu_password'";

    include_once("database.php");

    $result = @mysql_query($selectstusql) or die("学生登录失败:".mysql_error()."<br/>");

    if(mysql_num_rows($result) > 0) {
        
        setcookie("stu_number",$stu_number,time()+60*60*24*7);
      
        header("Location:notice.php");

    } else {
        //输入的用户名和密码不存在
        echo "<script>alert(\"用户名或密码错误!\");</script>";
    }
}
?>
<!-- 这里是jQuery -->
<script src="//code.jquery.com/jquery.js"></script>
<!-- 这里是Bootstrap JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
<script>
   $(function () {
      $('#myTab li:eq(1) a').tab('show');
   });
</script>

 
